package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightRefundRequest;
import com.ktgj.flight.service.IFlightRefundRequestService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 退款申请Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/request")
public class FlightRefundRequestController extends BaseController
{
    @Autowired
    private IFlightRefundRequestService flightRefundRequestService;

    /**
     * 查询退款申请列表
     */
    @PreAuthorize(hasPermi = "flight:request:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightRefundRequest flightRefundRequest)
    {
        startPage();
        List<FlightRefundRequest> list = flightRefundRequestService.selectFlightRefundRequestList(flightRefundRequest);
        return getDataTable(list);
    }

    /**
     * 导出退款申请列表
     */
    @PreAuthorize(hasPermi = "flight:request:export")
    @Log(title = "退款申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightRefundRequest flightRefundRequest) throws IOException
    {
        List<FlightRefundRequest> list = flightRefundRequestService.selectFlightRefundRequestList(flightRefundRequest);
        ExcelUtil<FlightRefundRequest> util = new ExcelUtil<FlightRefundRequest>(FlightRefundRequest.class);
        util.exportExcel(response, list, "退款申请数据");
    }

    /**
     * 获取退款申请详细信息
     */
    @PreAuthorize(hasPermi = "flight:request:query")
    @GetMapping(value = "/{refundRequestId}")
    public AjaxResult getInfo(@PathVariable("refundRequestId") Long refundRequestId)
    {
        return AjaxResult.success(flightRefundRequestService.selectFlightRefundRequestById(refundRequestId));
    }

    /**
     * 新增退款申请
     */
    @PreAuthorize(hasPermi = "flight:request:add")
    @Log(title = "退款申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightRefundRequest flightRefundRequest)
    {
        return toAjax(flightRefundRequestService.insertFlightRefundRequest(flightRefundRequest));
    }

    /**
     * 修改退款申请
     */
    @PreAuthorize(hasPermi = "flight:request:edit")
    @Log(title = "退款申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightRefundRequest flightRefundRequest)
    {
        return toAjax(flightRefundRequestService.updateFlightRefundRequest(flightRefundRequest));
    }

    /**
     * 删除退款申请
     */
    @PreAuthorize(hasPermi = "flight:request:remove")
    @Log(title = "退款申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refundRequestIds}")
    public AjaxResult remove(@PathVariable Long[] refundRequestIds)
    {
        return toAjax(flightRefundRequestService.deleteFlightRefundRequestByIds(refundRequestIds));
    }
}
